const domainName = getApp().globalData.domainName
const parameter = getApp().globalData.parameter

// 加载机构列表
const load_jg_list=(that,jg_status,page_no)=>{
  wx.showLoading({
    title: 'loading……',
  })
  wx.request({
    url: domainName + '/load_jg_list',
    data: {
      jg_status:jg_status,
      page_no:page_no,
    },...parameter,
    success: res => {
      let jg_list = res.data.jg_list
      if(that.page_no==0){
        that.setData({
          jg_list:jg_list,
        })
      }else{
        that.setData({
          jg_list:that.data.jg_list.concat(jg_list),
        })
      }
      that.page_no += 1

      if(jg_list.length==0){
        that.setData({
          no_more:true
        })
      }
      wx.hideLoading()
    },
  })
}


const update_jg_status=(that,jg_id,set_status)=>{
  wx.request({
    url: domainName + '/update_jg_status',
    data: {
      jg_id:jg_id,
      set_status:set_status,
    },...parameter,
    success: res => {
      that.page_no = 0
      if(res.data.update_res){
        wx.showToast({
          title: '更新完成！',
          duration: 1500,
          icon: 'success',
          mask: true,
        })
        load_jg_list(that,that.jg_status,0)
      }
    },
  })
}


// 变更机构负责人
const update_jg_header=(that,jg_id, phone)=>{
  wx.request({
    url: domainName + '/update_jg_header',
    data: {
      jg_id:jg_id,
      phone:phone,
    },...parameter,
    success: res => {
      if(res.data.update_res){
        wx.showToast({
          title: '更变成功！',
          duration: 1500,
          icon: 'success',
        })
        that.onShow()
      }
    },
  })
}

module.exports={
  update_jg_status:update_jg_status,
  load_jg_list:load_jg_list,
  update_jg_header:update_jg_header,
}